﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Visio.ForwardEngineer.DataModel
{
    /// <summary>
    /// Holds the structure of a FOREIGN key constraint
    /// </summary>
    public class ForeignKeyStructure
    {
        //  This structure has been imported from SMO, to have a standard naming and
        //  avoid the need to load SMO for a simple tool. :=
        public enum ForeignKeyAction
        {
            NoAction = 0,
            Cascade = 1,
            SetNull = 2,
            SetDefault = 3,
        }
        public string Name;                         // Name of the constraint
        public TableStructure ReferencedTable;      // The referenced table
        public ForeignKeyAction DeleteAction;       // Action to perform on DELETE
        public ForeignKeyAction UpdateAction;       // Action to perform on UPDATE
        public ColumnList SourceColumns;            // List of all the referencing columns in the source
        public ColumnList ReferencedColumns;        // List of all the referenced column in the destination

        /// <summary>
        /// Standard constructor for a foreign key
        /// </summary>
        public ForeignKeyStructure()
        {
            DeleteAction = ForeignKeyAction.NoAction;
            UpdateAction = ForeignKeyAction.NoAction;
            SourceColumns = new ColumnList();
            ReferencedColumns = new ColumnList();
        }
    }

    /// <summary>
    /// Dictionary of foreign keys
    /// </summary>
    public class ForeignKeyList : Dictionary<string, ForeignKeyStructure>
    {
        /// <summary>
        /// Adds a new foreign key indexing it by name
        /// </summary>
        /// <param name="newRelationship"></param>
        public void Add(ForeignKeyStructure newRelationship)
        {
            this.Add(newRelationship.Name, newRelationship);
        }
    }
}
